<?php
if (isset($_SESSION["usuario"])) {
    include_once '../control/conexao.php';
    include_once '../model/menu.class.php';
    include_once '../model/menuDAO.class.php';
    include_once '../model/submenu.class.php';
    include_once '../model/submenuDAO.class.php';
    ?>
    <nav class = "navbar navbar-inverse  navbar-fixed-top" role = "navigation">
        <!--Brand and toggle get grouped for better mobile display -->
        <div class="navbar-header">
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class = "navbar-brand" href = "http://www.etb.com.br" target="_blank">CEP - ETB</a>            
        </div>
        <div class="collapse navbar-collapse navbar-ex1-collapse">
            <ul class = "nav navbar-nav side-nav">
                <?php
                $perfil = $_SESSION['usuario']->id_perfil;
                $menuDAO = new menuDAO();
                $arMenu = $menuDAO->listar_por_perfil($perfil);
                $ln = count($arMenu);
                $_SESSION['arPagina'] = array();
                for ($i = 0; $i < $ln; $i++) {
                    $_SESSION['arPagina'][] = $arMenu[$i]->menu_link;
                    $submenuDAO = new submenuDAO();
                    $arSubMenu = $submenuDAO->listar_por_menu($perfil, $arMenu[$i]);
                    $num = count($arSubMenu);
                    ?>
                    <li class = "dropdown">
                        <?php
                        if ($arMenu[$i]->menu_link != "#") {
                            ?>
                            <a href = "<?php echo $arMenu[$i]->menu_link ?>"><i class = "glyphicon glyphicon-<?php echo $arMenu[$i]->menu_icone ?>"></i> <?php echo utf8_encode($arMenu[$i]->menu_nome) ?></a>                        
                            <?php
                            for ($c = 0; $c < $num; $c++) {
                                $_SESSION['arPagina'][] = $arSubMenu[$c]->submenu_link;
                            }
                        } else {
                            ?>
                            <a href = "#" class = "dropdown-toggle" data-toggle = "dropdown"><i class = "glyphicon glyphicon-<?php echo $arMenu[$i]->menu_icone ?>"></i> <?php echo utf8_encode($arMenu[$i]->menu_nome) ?> <b class = "caret"></b></a>
                            <ul class = "dropdown-menu">
                                <?php
                                for ($c = 0; $c < $num; $c++) {
                                    $_SESSION['arPagina'][] = $arSubMenu[$c]->submenu_link;
                                    if ($arSubMenu[$c]->submenu_show == '1') {
                                        ?>
                                        <li><a href = "<?php echo $arSubMenu[$c]->submenu_link ?>"><i class = "glyphicon glyphicon-<?php echo $arSubMenu[$c]->submenu_icone ?>"></i> <?php echo utf8_encode($arSubMenu[$c]->submenu_nome) ?></a></li>
                                        <?php
                                    }
                                }
                                ?>
                            </ul>
                        <?php } ?>
                    </li> 
                <?php } ?>
            </ul>
            <ul class = "nav navbar-nav navbar-right navbar-user navbar-collapse">
                <li class = "dropdown user-dropdown">
                    <a href = "#" class = "dropdown-toggle" data-toggle = "dropdown"><i class = "glyphicon glyphicon-user"></i> <?php echo $_SESSION['usuario']->usuario_nick ?> <b class="caret"></b></a>
                    <ul class="dropdown-menu">
                        <li><a href="../control/processa_logout.php"><i class="glyphicon glyphicon-off"></i> Sair </a></li>                            
                    </ul>
                </li>
            </ul>
        </div>
    </nav><!-- /.navbar-collapse -->
<?php } else { ?>
    <nav class = "navbar navbar-inverse navbar-fixed-top" role = "navigation">
        <ul class = "nav navbar-nav side-nav">
            <img src = "img/sigest1.png" class = "img-responsive">
        </ul>
        <nav class = "navbar navbar-inverse navbar-fixed-top" role = "navigation">            
            <div class = "navbar-header">
                <a class = "navbar-brand" href = "http://www.etb.com.br">Centro de Ensino Profissionalizante - Escola Técnica de Brasília</a>
            </div>            
        </nav>
    </nav>
<?php } ?>
